//package gui;
//
//import java.awt.Color;
//import java.awt.Dimension;
//import java.awt.Graphics;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import java.awt.image.BufferedImage;
//import java.io.File;
//import java.io.IOException;
//
//import javax.imageio.ImageIO;
//import javax.swing.JOptionPane;
//
//public class QuestionMenu extends javax.swing.JPanel {
//	
//	int seconds =30;
//	boolean answerFieldFocusGained;
//    int screenSize = 2;
//    BufferedImage image;   // holds image for panel background
//    int w, h;              // holds dimensions for panel
//    
//    /** Creates new form QuestionMenu */
//    public QuestionMenu(int screenSize) {
//       
//    	this.screenSize = screenSize;
//    	 // read the image file and set the custom panel dimensions based on
//        // image dimensions.
//        try {
//        	if (screenSize == 1)
//        		image = ImageIO.read(new File("black_chips800X600.JPG"));  // holds smaller image
//        	else if (screenSize == 2)
//        		image = ImageIO.read(new File("black_chips2.JPG"));  // holds larger image
//            w = image.getWidth();                         // holds image width
//            h = image.getHeight();                        // holds image height
//            // throw exception and exit if file problems
//        } catch (IOException ioe) {
//            System.out.println(ioe);
//            System.exit(0);
//        }
//
//        initComponents();
//        
//    }
//    
// // Generic method to get preferred size
//    public Dimension getPreferredSize() {
//        return new Dimension(w, h);
//    }
//
//    // override of paintComponent to use image
//    public void paintComponent(Graphics g) {
//        super.paintComponent(g);
//
//        g.drawImage(image, 0, 0, this);
//    }    
//    /** This method is called from within the constructor to
//     * initialize the form.
//     * WARNING: Do NOT modify this code. The content of this method is
//     * always regenerated by the Form Editor.
//     */
//    @SuppressWarnings("unchecked")
//    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
//    
//    private void initComponents() {
//
//        QuestionLabel = new javax.swing.JLabel();
//        AnswerField = new javax.swing.JTextField();
//        SubmitButton = new javax.swing.JButton();
//        TimerLabel = new javax.swing.JLabel();
//
//       
//
//        QuestionLabel.setText("Question:");
//
//        AnswerField.setText("Answer Field");
//
//        SubmitButton.setText("Submit");
//        SubmitButton.addActionListener(new java.awt.event.ActionListener() {
//            public void actionPerformed(java.awt.event.ActionEvent evt) {
//                SubmitButtonActionPerformed(evt);
//            }
//        });
//        
//        AnswerField.addFocusListener(new java.awt.event.FocusAdapter() {
//            public void focusGained(java.awt.event.FocusEvent evt) {
//                answerFieldFocusGained(evt);
//            }
//        });
//
//        TimerLabel.setText("TIMER: " + seconds);
//
//        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
//        setLayout(layout);
//        layout.setHorizontalGroup(
//            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//            .addGroup(layout.createSequentialGroup()
//                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
//                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
//                        .addGap(82, 82, 82)
//                        .addComponent(QuestionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE))
//                    .addGroup(layout.createSequentialGroup()
//                        .addContainerGap()
//                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
//                            .addGroup(layout.createSequentialGroup()
//                                .addComponent(TimerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
//                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
//                                .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
//                            .addComponent(AnswerField, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
//                        .addGap(93, 93, 93)))
//                .addContainerGap(163, Short.MAX_VALUE))
//        );
//        layout.setVerticalGroup(
//            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
//            .addGroup(layout.createSequentialGroup()
//                .addGap(91, 91, 91)
//                .addComponent(QuestionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
//                .addGap(45, 45, 45)
//                .addComponent(AnswerField, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
//                .addGap(53, 53, 53)
//                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
//                    .addComponent(SubmitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
//                    .addComponent(TimerLabel))
//                .addGap(75, 75, 75))
//        );
//        
//		AnswerField.setForeground(Color.gray);
//
//    }// </editor-fold>//GEN-END:initComponents
//
//    private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitButtonActionPerformed
//        // TODO add your handling code here:
//    	try{    	
//
//	    	if(Integer.parseInt(AnswerField.getText())==0)
//	    	{
//	    		//MenuCycling.guess(1);
//	    		MenuCycling.client.sendAnswer(MenuCycling.g.getGameID(), Integer.parseInt(AnswerField.getText()));
//	    		do {
//					MenuCycling.sleepyTime();
//				} while (!MenuCycling.bettingOddsReceived);
//	    	}
//	    	else 
//	    	{
//	    		answerFieldFocusGained = false;
//	    		AnswerField.setForeground(Color.gray);
////	    		MenuCycling.guess(Integer.parseInt(AnswerField.getText()));
//	    		MenuCycling.client.sendAnswer(MenuCycling.g.getGameID(), Integer.parseInt(AnswerField.getText()));
//	    		do {
//					MenuCycling.sleepyTime();
//				} while (!MenuCycling.bettingOddsReceived);
//	    		MenuCycling.displayBetScreen();
//	    	}
//    	}
//    	catch(NumberFormatException number){
//    		JOptionPane.showMessageDialog(null, "Invalid Bet");
//    	}
//    }//GEN-LAST:event_SubmitButtonActionPerformed
//    
//    private void answerFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_gameNameFieldFocusGained
//        // TODO add your handling code here:
//        if(answerFieldFocusGained == false)
//        {
//            AnswerField.setText("");
//            AnswerField.setForeground(Color.black);
//            answerFieldFocusGained = true;
//        }
//    }//GEN-LAST:event_gameNameFieldFocusGained
//    
////  ActionListener for timer question screen
//    public class TimerListener implements ActionListener {
//           public void actionPerformed(ActionEvent e) {
//           // go back to the beginning 
//        	if (seconds == 0) {
//        		answerFieldFocusGained = false;
//        		AnswerField.setForeground(Color.gray);
//        		MenuCycling.guess(1);
//        		MenuCycling.displayBetScreen();
//        		seconds = 30;
//        	}
//           // otherwise get next message in array
//           else{
//        	   TimerLabel.setText("TIMER: " + seconds);
//        	   seconds--;
//        	   repaint();
//           }
//           
//             }  // end of actionPerformed
//     }   // end of TimerListener
//			
//    /**
//     * @param args the command line arguments
//     */
//    
//    
//    // initializes the screen's text labels
//    public void setQuestion(){
//    	QuestionLabel.setText("Question: "  + MenuCycling.getQuestion());
//    }
//    
//    public void clearFields(){
//    	AnswerField.setText("Answer Field");
//    	TimerLabel.setText("TIMER: " + seconds);
//    }
//    
//    // Variables declaration - do not modify//GEN-BEGIN:variables
//    private javax.swing.JTextField AnswerField;
//    private javax.swing.JLabel QuestionLabel;
//    private javax.swing.JButton SubmitButton;
//    private javax.swing.JLabel TimerLabel;
//    // End of variables declaration//GEN-END:variables
//}










package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

public class QuestionMenu extends javax.swing.JPanel {
	
	int seconds =30;
	boolean answerFieldFocusGained;
    int screenSize = 2;
    BufferedImage image;   // holds image for panel background
    int w, h;              // holds dimensions for panel
    
    /** Creates new form QuestionMenu */
    public QuestionMenu(int screenSize) {
       
    	this.screenSize = screenSize;
    	 // read the image file and set the custom panel dimensions based on
        // image dimensions.
        try {
        	if (screenSize == 1)
        		image = ImageIO.read(new File("black_chips800X600.JPG"));  // holds smaller image
        	else if (screenSize == 2)
        		image = ImageIO.read(new File("black_chips2.JPG"));  // holds larger image
            w = image.getWidth();                         // holds image width
            h = image.getHeight();                        // holds image height
            // throw exception and exit if file problems
        } catch (IOException ioe) {
            System.out.println(ioe);
            System.exit(0);
        }

        initComponents();
        
    }
    
 // Generic method to get preferred size
    public Dimension getPreferredSize() {
        return new Dimension(w, h);
    }

    // override of paintComponent to use image
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        g.drawImage(image, 0, 0, this);
    }    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    
    private void initComponents() {

        QuestionLabel = new javax.swing.JLabel();
        AnswerField = new javax.swing.JTextField();
        SubmitButton = new javax.swing.JButton();
        TimerLabel = new javax.swing.JLabel();

       

        QuestionLabel.setText("Question:");

        AnswerField.setText("Answer Field");

        SubmitButton.setText("Submit");
        SubmitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SubmitButtonActionPerformed(evt);
            }
        });
        
        AnswerField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                answerFieldFocusGained(evt);
            }
        });

        TimerLabel.setText("TIMER: " + seconds);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(82, 82, 82)
                        .addComponent(QuestionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(TimerLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                                .addComponent(SubmitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(AnswerField, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(93, 93, 93)))
                .addContainerGap(163, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(91, 91, 91)
                .addComponent(QuestionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(AnswerField, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(53, 53, 53)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SubmitButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(TimerLabel))
                .addGap(75, 75, 75))
        );
        
		AnswerField.setForeground(Color.gray);

    }// </editor-fold>//GEN-END:initComponents

    private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitButtonActionPerformed
        // TODO add your handling code here:
    	try{    	

	    	if(Integer.parseInt(AnswerField.getText())==0)
	    	{
	    		//MenuCycling.guess(1);
	    		MenuCycling.client.sendAnswer(MenuCycling.g.getGameID(), Integer.parseInt(AnswerField.getText()));
	    		do {
					MenuCycling.sleepyTime();
				} while (!MenuCycling.bettingOddsReceived);
	    	}
	    	else 
	    	{
	    		answerFieldFocusGained = false;
	    		AnswerField.setForeground(Color.gray);
//	    		MenuCycling.guess(Integer.parseInt(AnswerField.getText()));
	    		MenuCycling.client.sendAnswer(MenuCycling.g.getGameID(), Integer.parseInt(AnswerField.getText()));
	    		do {
					MenuCycling.sleepyTime();
				} while (!MenuCycling.bettingOddsReceived);
	    		MenuCycling.displayBetScreen();
	    	}
    	}
    	catch(NumberFormatException number){
    		JOptionPane.showMessageDialog(null, "Invalid Bet");
    	}
    }//GEN-LAST:event_SubmitButtonActionPerformed
    
    private void answerFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_gameNameFieldFocusGained
        // TODO add your handling code here:
        if(answerFieldFocusGained == false)
        {
            AnswerField.setText("");
            AnswerField.setForeground(Color.black);
            answerFieldFocusGained = true;
        }
    }//GEN-LAST:event_gameNameFieldFocusGained
    
//  ActionListener for timer question screen
    public class TimerListener implements ActionListener {
           public void actionPerformed(ActionEvent e) {
           // go back to the beginning 
        	if (seconds == 0) {
        		answerFieldFocusGained = false;
        		AnswerField.setForeground(Color.gray);
        		MenuCycling.guess(1);
        		MenuCycling.displayBetScreen();
        		seconds = 30;
        	}
           // otherwise get next message in array
           else{
        	   TimerLabel.setText("TIMER: " + seconds);
        	   seconds--;
        	   repaint();
           }
           
             }  // end of actionPerformed
     }   // end of TimerListener
			
    /**
     * @param args the command line arguments
     */
    
    
    // initializes the screen's text labels
    public void setQuestion(){
    	QuestionLabel.setText("Question: "  + MenuCycling.getQuestion());
    }
    
    public void clearFields(){
    	AnswerField.setText("Answer Field");
    	TimerLabel.setText("TIMER: " + seconds);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AnswerField;
    private javax.swing.JLabel QuestionLabel;
    private javax.swing.JButton SubmitButton;
    private javax.swing.JLabel TimerLabel;
    // End of variables declaration//GEN-END:variables
}











